package com.pks.datacenter.service.basic;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.pks.datacenter.config.RedisKeyConfig;
import com.pks.datacenter.entity.basic.DbInfo;
import com.pks.datacenter.handler.RedisHandler;
import com.pks.datacenter.mapper.basic.DbInfoMapper;
import com.pks.web.mybatis.service.BasicServiceImpl;

@Component("dbInfoService")
public class DbInfoServiceImpl extends BasicServiceImpl<DbInfo, Long, DbInfoMapper> implements DbInfoService {

	@Autowired
	private DbInfoMapper dbInfoMapper;
	@Resource
	private RedisHandler redisHandler;

	@Override
	protected DbInfoMapper getMapper() {
		return dbInfoMapper;
	}

	@Override
	public DbInfo findDbById(Long dbId) {
		DbInfo dbInfo = null;
		if (dbId != null) {
			Object obj = redisHandler.get(RedisKeyConfig.KEY_INFO_DBINFO_PREFIX + dbId);
			if (obj != null) {
				dbInfo = (DbInfo) obj;
			} else {
				dbInfo = dbInfoMapper.findById(dbId);
				redisHandler.set(RedisKeyConfig.KEY_INFO_DBINFO_PREFIX + dbId, dbInfo, RedisKeyConfig.CACHE_TIME);
			}
		}
		return dbInfo;
	}
	
}
